package breeze.lepei.der.main_view.model;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import breeze.lepei.der.R;
import java.util.List;
import android.view.LayoutInflater;
import android.support.v7.widget.CardView;
import android.widget.GridLayout.LayoutParams;
import android.widget.FrameLayout;
import breeze.lepei.der.utils.MLog;

public class StuHisAdapter extends RecyclerView.Adapter<StuHisAdapter.MyViewHolder> {
	
	private Context context;
	private List<StuHistoryExamModel.Obj> list;
	
	public StuHisAdapter(Context context,List<StuHistoryExamModel.Obj> data){
		this.context=context;
		this.list=data;
	}

	@Override
	public StuHisAdapter.MyViewHolder onCreateViewHolder(ViewGroup p1, int p2) {
		View view=LayoutInflater.from(context).inflate(R.layout.view_recycler_item,null);
		return new MyViewHolder(view);
	}

	@Override
	public void onBindViewHolder(StuHisAdapter.MyViewHolder p1, int p2) {
		MLog.log(TAG,"数值：",String.valueOf(p2));
		if(p2==0){
			ViewGroup.MarginLayoutParams vm=(ViewGroup.MarginLayoutParams)p1.cardview.getLayoutParams();
			vm.leftMargin=70;
			p1.cardview.setLayoutParams(vm);
		}else{
			ViewGroup.MarginLayoutParams vm=(ViewGroup.MarginLayoutParams)p1.cardview.getLayoutParams();
			vm.leftMargin=10;
			p1.cardview.setLayoutParams(vm);
		}
		StuHistoryExamModel.Obj obj=list.get(p2);
		p1.examName.setText(obj.getExamName());
		StringBuilder sb=new StringBuilder();
		sb.append("学校最高").append(String.valueOf(obj.getSchoolHighScore())).append("分，")
			.append("学校均分").append(String.valueOf(obj.getSchoolAvgScore())).append("分，")
			.append(obj.getStudentName()).append("（考号："+obj.getExamNo()+"）")
			.append("得分").append(String.valueOf(obj.getScore())).append("，学校排名").append(String.valueOf(obj.getSchoolRank())).append("名。");
		p1.examInfo.setText(sb);
	}

	@Override
	public int getItemCount() {
		return list.size();
	}
    
    public static final String TAG = "StuHisAdapter";
    
    class MyViewHolder extends RecyclerView.ViewHolder{
		TextView examName,examInfo;
		CardView cardview;
		public MyViewHolder(View view){
			super(view);
			examName=view.findViewById(R.id.recycler_examname);
			examInfo=view.findViewById(R.id.recycler_exam_info);
			cardview=view.findViewById(R.id.view_recycler_itemCardView);
		}
	}
    
}
